import axios from 'axios'

axios.defaults.baseURL = 'http://127.0.0.1:7777'
axios.defaults.timeout = 30000
axios.defaults.headers.common['Authorization'] = ''
axios.defaults.headers.post['Content-Type'] = 'application/json'

export function fetch (url, params) {
  return new Promise((resolve, reject) => {
    axios.post(url, params)
      .then(response => {
        resolve(response.data)
      })
      .catch((error) => {
        reject(error)
      })
  })
}

export function fetchPost (url, params, token) {
  return new Promise((resolve, reject) => {
    axios({
      method: 'post',
      url: url,
      headers: token,
      data: params
    })
      .then(response => {
        resolve(response.data)
        // console.log('resolve',response)
      })
      .catch(error => {
        reject(error)
        // console.log('error',error)
      })
  })
}

export default axios
